<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class PurchaseModel extends Model
{
    public function getList($status,$startime,$endtime,$supplier,$warehouse,$number)
    {
        $where =[];
        if(!empty($status)){
            $where['status'] =['like', "%".$status."%"];
        }
        if(!empty($startime) && !empty($endtime)){
            $where['create_time'] =['between',[$startime,$endtime]];
        }
        if(!empty($supplier)){
            $where['supplier'] =['like', "%".$supplier."%"];
        }
        if(!empty($warehouse)){
            $where['warehouse'] =['like', "%".$warehouse."%"];
        }
        if(!empty($number)){
            $where['number'] =['like', "%".$number."%"];
        }
        $list =Db::name('purchase')->where($where)->order('create_time desc')->select();
        foreach($list as $k=>$v){
            $list[$k]['create_time'] =date('Y-m-d H:i:s',$v['create_time']);
            $list[$k]['relation_number'] =Db::name('storage')->where('relation_number',$v['odd_number'])->value('odd_number');
        }
        //$list['total'] =count($list);
        //print_r($list);die;
        return $list;
    }
    public function getAdd($data)
    {
        $arr =Db::name('purchase')->insertGetId($data);
        return $arr;
    }
}